package algorithm;

import java.util.ArrayList;

public class leetcode_0234 {
    public boolean isPalindrome(ListNode head) {
        if(head==null||head.next==null) return true;
        ArrayList<Integer> list=new ArrayList<>();
        ListNode p=head.next;
        list.add(head.val);
        while(p!=null){

            list.add(p.val);

            p=p.next;
        }
        int len=list.size();
        for(int i=0;2*i<len-1;++i){
            if(list.get(i)!= list.get(len-1-i)){
                return false;
            }
        }
        return true;
    }
}
